home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / A.D. Software / OOFILE / Buildable, limited OOFILE / samples / ooftst02.cpp < prev    next >
C/C++ Source or Header  |  1996-02-07  |  2KB  |  80 lines

  1. // Copyright 1994 A.D. Software. All Rights Reserved
  2.  
  3. // OOFTEST2
  4.  
  5. // This sample tests the database backend by creating a pair of tables
  6. // and storing and retrieving indexed data via traversal paths.
  7.  
  8. // Simple stream I/O is used to interact with the user.
  9. #include "oofile.hpp"
  10.  
  11. #include "ooftst02.inc"
  12.  
  13. int main()
  14. {
  15.     cout << "OOFILE Validation Suite - Test 2\n"
  16.          << "Simple test to store some data and retrieve it" << endl
  17.          << "using a relation joining over a field and showing" << endl
  18.          << "iterators on related tables and 1-many relations" << endl << endl;
  19.     
  20.     if (dbConnect::fileExists("ooftst02.db")) {
  21.         theDB.openConnection("ooftst02.db");
  22.     }
  23.     else {
  24.         theDB.newConnection("ooftst02.db");
  25.         Patients.AddTestData();
  26.     }
  27.  
  28.     cout << theDB;
  29.     
  30.     Patients.setSortOrder(Patients.LastName);
  31.     Patients.start(); 
  32.     while (Patients.more()) {
  33.         cout << Patients.PatientNo << '\t' 
  34.              << Patients.LastName << endl;
  35.         if (Patients.Visits->count()==0)
  36.             cout << "no visits" << endl;
  37.         else {
  38.             Patients.Visits->start(); 
  39.             while (Patients.Visits->more()) {
  40.                 cout << '\t' << Patients.Visits->VisitDate << '\t'
  41.                       << Patients.Visits->Why << endl;
  42.                 Patients.Visits->next();
  43.             }
  44.         }
  45.         cout << endl;
  46.         Patients.next();
  47.     }
  48.  
  49.     cout << endl << "Now repeating the process using a dbView instead of explicitly" 
  50.          << endl << "iterating over the related file." << endl;
  51.     dbView relatedVisits(Patients.Visits);
  52.     relatedVisits << Patients.Visits->VisitDate << Patients.Visits->Why;
  53.     Patients.start(); 
  54.     while (Patients.more()) {
  55.         cout << Patients.PatientNo << '\t' 
  56.              << Patients.LastName << endl;
  57.         if (relatedVisits.source()->empty())
  58.             cout << "no visits" << endl;
  59.         else 
  60.             cout << relatedVisits << endl;
  61.         cout << endl;
  62.         Patients.next();
  63.     }
  64.  
  65. /* Coming in v1.2 - search by related fields
  66.     cout << "Now finding the Flu sufferers: " << endl;
  67.     Patients.search(Patients.Visits->Why=="Flu");
  68.     cout << Patients << endl;
  69. */
  70.  
  71.     Patients.setSortOrder(Patients.Othernames);
  72.     cout << "Now dumping the entire database, with patients sorted by Othernames: " << endl << theDB;
  73.     
  74.     cout << "Description of database schema: " << endl;
  75.     theDB.describe(cout);
  76.     
  77.     cout << "Test Completed" << endl;
  78.     
  79.     return EXIT_SUCCESS;
  80. }